﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BanVeXemPhim_Presentation
{
    public partial class FormMHDangNhap : Form
    {
        public FormMHDangNhap()
        {
            InitializeComponent();
        }

        private NhanVienControl _nhanVienControl;

        private FormMHChinh _manHinhChinh;


        public FormMHChinh ManHinhChinh
        {
            get { return _manHinhChinh; }
            set { _manHinhChinh = value; }
        }

        public NhanVienControl NhanVienControl
        {
            get { return _nhanVienControl; }
            set { _nhanVienControl = value; }
        }
        private void buttonDangNhap_Click(object sender, EventArgs e)
        {
            NhanVienDTO nhanVienDto=new NhanVienDTO();
            nhanVienDto.Username = this.textBoxTenDangNhap.Text;
            nhanVienDto.Password = this.textBoxMatKhau.Text;
            KhoiTaoNhanVienControl();
            int result = _nhanVienControl.KiemTraDangNhap(nhanVienDto);
            //code test 
            if(result==0)
            {
                MessageBox.Show("Username không tồn tại hoặc password không đúng!!");
                return;
            }
            else if(result==2)
            {
                this.Hide();
                this.ManHinhChinh.ShowMHBanVe();
                this.Dispose();

            }
            else if(result==1)
            {

                this.Hide();
                this.ManHinhChinh.ShowMHAdmin();
                this.Dispose();
            }
        }

        public bool KiemTraDangNhap(string username,string pass)
        {
            return false;
        }

        private void FormMHDangNhap_Load(object sender, EventArgs e)
        {
            //Khoi tao
            string s = Application.StartupPath;
            DataProvider.ConnectionString = @"Data Source=localhost\SQLEXPRESS;AttachDbFilename=" + s +
                                            "\\DatabaseCinema.mdf" +
                                            ";Integrated Security=True;Connect Timeout=30;User Instance=True";
            _nhanVienControl=new NhanVienControl();
        }
        public void KhoiTaoNhanVienControl()
        {
            if(_nhanVienControl==null)
            {
                _nhanVienControl = new NhanVienControl(); 
            }
        }


    }
}
